#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
using namespace std;
#include <vector>
vector<int> minOperations(string boxes) {
    //int cur = 0;
    //vector<int> ans(boxes.size(), 0);
    //for (cur = 0; cur < boxes.size(); cur++)
    //{
    //    for (int j = 0; j < boxes.size(); j++)
    //    {
    //        if (j != cur)
    //        {
    //            int num = 0;
    //            num = j - cur < 0 ? cur - j : j - cur;
    //            ans[cur] += num * (boxes[j] - '0');
    //        }
    //    }
    //}


    int n = boxes.size();
    int countLeft = boxes[0] == '0' ? 0 : 1;
    int countRight = boxes[n - 1] == '0' ? 0 : 1;
    vector<int> left(n, 0);
    vector<int> right(n, 0);
    for (int i = 1; i < n; i++)
    {
        left[i] = left[i - 1] + countLeft;
        if (boxes[i] == '1')
            countLeft++;
    }

    for (int i = n - 1 - 1; i >= 0; i--)
    {
        right[i] = right[i + 1] + countRight;
        if (boxes[i] == '1')
            countRight++;
    }
    vector<int> ans(n, 0);
    for (int i = 0; i < n; i++)
    {
        ans[i] = left[i] + right[i];
    }
    return ans;

}